<?php

namespace App\Resource\Api;

use App\Model\ActivityUserInvite;
use App\Model\AgentOrder;
use App\Traits\ResourceWith;
use Hyperf\Resource\Json\JsonResource;

class UserResource extends JsonResource
{
    use ResourceWith;

    /**
     * Transform the resource into an array.
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'nick_name' => $this->nick_name,
            'real_name' => $this->real_name,
            'address' => $this->address,
            'invite_code' => $this->invite_code,
            'birthday' => $this->birthday ?? '',
            'avatar' => $this->avatar,
            'sex' => $this->sex,
            'mobile' => $this->mobile,
            'token' => $this->token,
            'is_share' => $this->is_share,
            'is_agent' => AgentOrder::where('uid', $this->id)->exists(),
            'activity_invite_code' => $this->activity_invite_code,
            'is_bind_activity' => ActivityUserInvite::where('uid', $this->id)->count(),
        ];
    }
}
